package com.web.new12306.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.web.new12306.mvc.InnerDispatcherController;
import com.web.new12306.pojo.Ticket;
import com.web.new12306.pojo.Order;
import com.web.new12306.pojo.Page;
import com.web.new12306.pojo.Pager;
import com.web.new12306.service.OrderService;
import com.web.new12306.service.TicketService;
import com.web.new12306.service.impl.OrderServiceImpl;
import com.web.new12306.service.impl.TicketServiceImpl;

public class ManagerController extends InnerDispatcherController {
	/**
	 * @author 赵靖懿
	 */
	private static final long serialVersionUID = -8128936181765400012L;
	
	public void pageGatagridTicket(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		Integer page = Integer.valueOf(request.getParameter("page"));
		Integer rows = Integer.valueOf(request.getParameter("rows"));
		Integer startrow=(page-1)*rows;
		System.out.println("page:" + page + ";rows:" + rows);
		TicketService ts=new TicketServiceImpl();
		List<Ticket> data =ts.queryTickets(page, rows) ;
		int number=ts.number();
		System.out.println(number);
		Page page2=new Page();
		page2.setTotal(number);
		page2.setRows(data);
		
		response.setContentType("application/json");
		response.getWriter().append(JSON.toJSONString(page2));
		System.out.println(JSON.toJSONString(page2));
	}
	
	public void pageGatagridOrder(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		Integer page = Integer.valueOf(request.getParameter("page"));
		Integer rows = Integer.valueOf(request.getParameter("rows"));
		Integer startrow=(page-1)*rows;
		System.out.println("page:" + page + ";rows:" + rows);
		OrderService os=new OrderServiceImpl();
		List<Order> data =os.queryOrders(page, rows) ;
		int number=os.number();
		Pager page3=new Pager();
		page3.setTotal(number);
		page3.setRows(data);
		 
		response.setContentType("application/json");
		response.getWriter().append(JSON.toJSONString(page3));
		System.out.println(JSON.toJSONString(page3));
	}
	

}